#ifndef LIBACCENT_ALGORITHMS_COUNT_HPP
#define LIBACCENT_ALGORITHMS_COUNT_HPP

#include "accent/core.hpp"
#include "accent/algorithms/filter.hpp"
#include <cstddef>

namespace accent
{

  namespace detail
  {
    template <typename Range>
    std::size_t count_impl(Range r, single_pass_traversal_tag) {
      std::size_t n = 0;
      for (; !r.empty(); r.pop_front()) {
        ++n;
      }
      return n;
    }

    template <typename Range>
    std::size_t count_impl(Range r, random_access_traversal_tag) {
      return r.size();
    }
  }

  template <typename Range>
  std::size_t count(Range r) {
    return detail::count_impl(r, typename Range::traversal());
  }

  template <typename Range, typename Predicate>
  std::size_t count(Range r, Predicate p) {
    return count(filter(r, p));
  }

}

#endif
